#include<iostream>
using namespace std;

const int table_size = 12;

bool dxq_table[table_size][8]={ // table in CMEA order
	{ 1, 1, 1, 1, 1, 1, 1, 1 }, /*1 new*/	
	{ 0, 0, 1, 0, 0, 0, 0, 0}, /*2 Rename*/ 
	{ 0, 0, 1, 0, 0, 0, 0, 0}, /*3 Intra-volume move*/
	{ 0, 0, 1, 1, 1, 1, 1, 1}, /*4 Inter-volume move */
	{ 1, 0, 1, 1, 1, 1, 1, 1}, /*5 Copy  (target file) exe*/
	{ 0, 1, 1, 0, 0, 0, 0, 0}, /*6 modify content*/
	{ 0, 0, 1, 0, 0, 0, 0, 0}, /*7 modify general attr */
	{ 0, 1, 1, 0, 0, 0, 0, 0}, /*8 modify sum attr */
	{ 0, 0, 1, 0, 0, 0, 0, 0}, /*9 intra replace */
	{ 0, 0, 1, 0, 0, 0, 0, 0}, /*10 inter replace  */
	{ 0, 0, 0, 0, 0, 0, 0, 0}, /*11  */
	{ 0, 0, 0, 0, 0, 0, 0, 0} /*12  */
};
bool chg_table[table_size][8] = {} ;//table in MACE order

class timeRelation{
public:
	timeRelation(){
		data = new int*[8];
		for(int i=0; i<8; i++){
			data[i] = new int[8];
			for(int j=0; j<8; j++)
				data[i][j] = 0;
		}
	}
	virtual ~timeRelation(){
		for(int i=0; i<8; i++){
			delete[] data[i];
		}
		delete[] data;
	}

	template <int m, int n>
	void chgData(bool (&table)[m][n])
	{
		for(int i=0; i<table_size; i++){
			for(int j=0; j<8; j++){
				if(table[i][j]){
					for(int k=0; k<8; k++){
						if(!table[i][k])	
							data[j][k]++; //the bigger the value, the higher possibility that time j is later than time k
					}
				}
			}
		}
	}
	void output(){
		//the head of the result table
		cout<<"\t";
		for(int i=0; i<8; i++){
			cout<<i+1<<"\t";
		}		cout<<endl;
		//data. 
		for(int i=0; i<8; i++){
			cout<<i+1;
			for(int j=0; j<8; j++){
				cout<<"\t";
				if(i != j || true){//do not output the diagonal 
					cout<<data[i][j];
				}
			}
			cout<<endl;
		}
		for (int i = 0;i<8;i++)
			for (int j = 0;j<8;j++)
				if (data[i][j]||true)
					cout<<"{"<<i<<","<<j<<","<<data[i][j]<<"},";
	}
private:
	int **data;
};

void genChangeTable() {
	int colmap[] = {1,3,0,2,5,7,4,6};
	for (int i = 0;i<table_size;i++)
		for (int j=0;j<8;j++)
			chg_table[i][j] = dxq_table[i][colmap[j]];

}

int main()
{
	genChangeTable();
	timeRelation re;
	re.chgData(chg_table);
	re.output();
	return 0;
}